package cate.common.game.mail;

import cp.solution.business.game.component.NoticeParam;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

@NoteClass("给玩家发邮件的指令")
@ToString
public class MailCmd {

    /** send-mode范围内的明确列出来的玩家 */
    public static final byte ROLE_MODE_LIST = 0;
    /** send-mode范围内的在线的玩家 */
    public static final byte ROLE_MODE_ONLINE = 1;
    /** send-mode范围内的所有玩家 */
    public static final byte ROLE_MODE_ALL = 2;

    public static final long LIFETIME_ONE_MINUTE = 60_000;
    public static final long LIFETIME_ONE_HOUR = 3600_000;
    public static final long LIFETIME_ONE_DAY = 24*3600_000;
    public static final long LIFETIME_ONE_WEEK = 7*24*3600_000;

    public MailCmd() {
    }

    @NoteField(value = "筛选角色模式")
    public byte roleMode = ROLE_MODE_LIST;

    @NoteField(value = "指定游戏服ID")
    public int srvId;

    @NoteField(value = "玩家ID列表")
    public List<String> roleIdList;

    @NoteField(value = "邮件类型", detail = "默认为0")
    public byte type;

    @NoteField(value = "邮件标题")
    public String title;

    @NoteField(value = "邮件内容ID")
    public int contentId;

    @NoteField(value = "邮件内容参数")
    public List<NoticeParam> paramList;

    @NoteField(value = "奖励配置")
    public String rewardConf;

    @NoteField(value = "创建时间")
    public long createTime;

    @NoteField(value = "真正发出去的时间")
    public long sentTime;

    @NoteField(value = "因为什么操作得到该邮件")
    public int operation;

    @NoteField(value = "操作子类型")
    public int operationSub;

    @NoteField(value = "指令寿命", detail = "超过这个寿命时间还没有发送出去，就丢掉了")
    public long lifetime = LIFETIME_ONE_DAY;

    @NoteField("尝试发送的次数")
    public int tt;
    public int tt() { return this.tt; }

    public MailCmd addRole(String roleId) {
        this.roleMode = ROLE_MODE_LIST;
        if(this.roleIdList == null) {
            this.roleIdList = new ArrayList<>();
        }
        this.roleIdList.add(roleId);
        return this;
    }

    public MailCmd withRoleMode(byte v) {
        this.roleMode = v;
        return this;
    }

    public MailCmd withSrvId(int v) {
        this.srvId = v;
        return this;
    }

    public MailCmd withTitle(String v) {
        this.title = v;
        return this;
    }

    /** 直接设置为完全的文本内容 */
    public MailCmd withContent(String content) {
        this.contentId = 0;
        this.paramList = new ArrayList<>();
        this.paramList.add(new NoticeParam(content));
        return this;
    }

    public MailCmd withContent(int contentId, List<NoticeParam> paramList) {
        this.contentId = contentId;
        this.paramList = paramList;
        return this;
    }

    public MailCmd withReward(String cnf) {
        this.rewardConf = cnf;
        return this;
    }

    public MailCmd withOpr(int operation, int operationSub) {
        this.operation = operation;
        this.operationSub = operationSub;
        return this;
    }

    public MailCmd withOpr(int operation) {
        this.operation = operation;
        return this;
    }

    public MailCmd withLifetime(long v) {
        this.lifetime = v;
        return this;
    }

    /** 是否成功发送 */
    public boolean hasBeenSent() {
        return this.sentTime > 0;
    }
}
